package com.ziyun.erp.modules.store.storeGoodsCategory.service.impl;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import java.util.*;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;

import com.ziyun.erp.modules.store.storeGoodsCategory.dao.StoreGoodsCategoryTwdDao;
import com.ziyun.erp.modules.store.storeGoodsCategory.entity.StoreGoodsCategoryTwdEntity;
import com.ziyun.erp.modules.store.storeGoodsCategory.service.StoreGoodsCategoryTwdService;


@Service("storeGoodsCategoryTwdService")
public class StoreGoodsCategoryTwdServiceImpl extends ServiceImpl<StoreGoodsCategoryTwdDao, StoreGoodsCategoryTwdEntity> implements StoreGoodsCategoryTwdService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<StoreGoodsCategoryTwdEntity> page = this.selectPage(
                new Query<StoreGoodsCategoryTwdEntity>(params).getPage(),
                new EntityWrapper<StoreGoodsCategoryTwdEntity>()
                        .like(StringUtils.isNotBlank((String) params.get("categoryName")), "category_name", (String) params.get("categoryName"))
                        .eq(StringUtils.isNotBlank((String) params.get("categoryType")), "category_type", params.get("categoryType"))
                        .gt(StringUtils.isNotBlank((String) params.get("beginTime")), "create_time", params.get("beginTime"))
                        .lt(StringUtils.isNotBlank((String) params.get("endTime")), "create_time", params.get("endTime"))
                        .eq("del", 0)
                        .orderBy("create_time", false)
        );

        return new PageUtils(page);
    }

    /**
     * 伪删除
     *
     * @param id
     */
    public void deleteUpdate(Integer id) {
        Map<String, Object> map = new HashMap<>();
        map.put("del", 1);
        baseMapper.updateByMap(map, id);
    }

    public void deleteAllUpdate(String ids) {
        String[] split = ids.split(",");
        List<String> idList = new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            idList.add(split[i]);
        }
        Map<String, Object> map = new HashMap<>();
        map.put("del", 1);
        baseMapper.updateAllByMap(map, idList);
    }

    /**
     * 商品表远程搜索图文宝分类
     */
    public List<StoreGoodsCategoryTwdEntity> selectTwbList(Map<String, Object> params) {
        return this.baseMapper.selectTwbList(params);
    }

//  public List<StoreGoodsCategoryTwdEntity> selectTwbCategoryList(Map<String, Object> params) {
//      return this.baseMapper.selectTwbCategoryList(params);
//  }
}
